package cn.smxy.ln.controller;

import cn.smxy.ln.common.lang.Result;
import cn.smxy.ln.pojo.WorkRegister;
import cn.smxy.ln.service.WorkRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


/**
 * @author ln
 * @date 2022年05月20日 21:07
 */
@RestController
@RequestMapping("/workregister/consumer")
public class WorkRegisterConsumerController {

    @Autowired
    WorkRegisterService workRegisterService;

    @GetMapping("/list")
    public Result queryAll(@RequestParam(value = "teacherId", required = false) Long teacherId, @RequestParam(value = "projectId", required = false) Long projectId, @RequestParam(value = "workId", required = false) Long workId, @RequestParam(value = "workContent", required = false) String workContent, @RequestParam(value = "startTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime, @RequestParam(value = "endTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime, @RequestParam(value = "createTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date createTime) {
        return Result.succ(workRegisterService.queryAll(teacherId, projectId, workId, workContent, startTime, endTime, createTime));
    }

    @PostMapping("/save")
    public Result save(@RequestBody WorkRegister workRegister) {
        return Result.succ(workRegisterService.save(workRegister));
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam(value = "id") Long id) {
        return Result.succ(workRegisterService.delete(id));
    }

    @PostMapping("/update")
    public Result update(@RequestBody WorkRegister workRegister) {
        return Result.succ(workRegisterService.update(workRegister));
    }
}
